<?php
/**
 * Created by PhpStorm.
 * User: 郑合达
 * Date: 2019/3/12
 * Time: 17:22
 */

namespace app\admin\controller;


use app\model\EquipmentModel;
use think\Controller;
use app\model\DeviceInfoModel;
class Deviceinfo2 extends Controller
{
    /**
     * 1. 查询设备位置信息
     */
    public function info(){
        //所有设备号
        $gerEqu=EquipmentModel::where('equ_user','<>',0)->select();
        foreach ($gerEqu as $k=>$v) {
            $imei = $v->name;
            $list = $this->curl("http://api.huixun.me/open/device-info/{$imei}?token=4d9262b1a5da42779110baa9df648743");
            if ($list['code'] == 200 && $list['data']) {
                $id = DeviceInfoModel::where('imei', $list['data']['imei'])->value('id');
                if ($id == 0) {
                    $res = DeviceInfoModel::create($list['data']);
                } else {
                    $res = DeviceInfoModel::update($list['data'], ['id' => $id]);
                }
            }
        }
    }
    

    public function device(){
        return view('index');
    }
}